<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
    </head>

<style type="text/css">
    .formbox {
        height: 1px;
    }

    body {
        background-color: white;
    }
</style>

<body>
<div class="layui-row">
    <div class="layui-col-md2  formbox ">
    </div>

    <div class="layui-fluid layui-col-md8 layui-col-sm12 ">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 15px;" class="layui-row">
                <form class="layui-form" lay-filter="selfilter">
                    <div class="layui-form-item">
                        <label class="layui-form-label">apk上传：</label>
                        <div class="layui-input-block">
                            <a class="layui-btn" id="upFile"><i class="layui-icon layui-icon-upload"></i>预览</a>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="apkName" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用包名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="apkPackage" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片：</label>
                        <div class="layui-input-block">
                            <img id="apkPictureUrl" src="" width="200px" height="200px"><br>
                            <span style="color:red">*点击图片框上传图片</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">创建人：</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="adminName" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否公开：</label>
                        <div class="layui-input-block">
                            <select name="city" lay-verify="required" id="apkIsItPublic">
                                <option value="不公开">否</option>
                                <option value="公开">是</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">审核状态：</label>
                        <div class="layui-input-block">
                            <select name="city" lay-verify="required" id="apkShenhe">
                                <option value="未审核">未审核</option>
                                <option value="已审核">已审核</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0">
                                <button class="layui-btn layui-icon layui-icon-add-edit" lay-submit lay-filter="update"
                                        id="add">修改
                                </button>
                                <button class="layui-btn layui-icon layui-icon-close" id="back">
                                    取消
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="layui-col-md2 formbox">

            </div>
        </div>
    </div>
</div>
</div>

</body>
<script type="text/javascript">

        //进度条
        var element = layui.element;
        //上传
        var upload = layui.upload;
        //表单
        var form = layui.form;
        //图片
        var fileName = null;
        //文件
        var apkFile = null

        var a = layui.data("a");//取值
        $("#apkName").val(a.apk.apk_name);
        $("#apkPackage").val(a.apk.apk_package);
        var Image = "http://127.0.0.1:8080/upload/" + a.apk.apk_picture_url;
        $("#apkPictureUrl").attr('src', Image);
        $("#adminName").val(a.apk.admin_name);
        $("#apkIsItPublic").val(a.apk.apk_is_it_public);
        $("#apkShenhe").val(a.apk.apk_shenhe);
        form.render('select','selfilter');

        form.on('submit(update)',function(){

            if (fileName == null) {
                layer.msg("请先选择图像", {
                    icon: 2,
                    time:800
                });
                return false;
            }

            if(apkFile == null)
            {
                layer.msg('请先选择上传的apk文件', {
                    icon: 7
                })
                return false;
            }
            $.ajax({
                type: "post",
                url: '/admin/apk/updateApkByApkId',
                data: {
                    apkId:a.apk.apk_id,
                    apkName:$("#apkName").val(),
                    apkPackage: $("#apkPackage").val(),
                    apkPictureUrl: fileName,
                    adminName:$("#adminName").val(),
                    apkIsItPublic: $("#apkIsItPublic").val(),
                    apkShenhe: $("#apkShenhe").val(),
                    apkPackage:package,
                    apkVersion:versionCode,
                    apkMd5:MD5,
                    apkUrl:filePath
                },
                success: function(res) {
                    console.log(res)
                    if(res.code == 200) {
                        layer.msg('编辑成功', {
                            icon: 1
                        });
                        setTimeout(function() {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 1000);
                        return;
                    }
                    if(res.code==500) {
                        layer.msg(res.data, {
                            icon: 2
                        })
                    }
                },
                error: function(res) {
                    layer.msg('服务器异常或网络原因', {
                        icon: 2
                    });
                }
            });
            return false;
        });

        //图片上传
        upload.render({
            elem: '#apkPictureUrl',
            url: '/admin/fileinfo/upload/image',
            choose: function (obj) {
                fileName = null;
                //预览
                obj.preview(function (index, file, result) {
                    $("#apkPictureUrl").attr('src', result);
                });

            },
            done: function (res, index, upload) { //上传完成
                fileName = res.data; //传回来的新的文件名
            }

        });
        $('#back').click(function () {
            var index = parent.layer.getFrameIndex(window.name) //获取窗口索引
            parent.layer.close(index)    //关闭弹出层
        })

        //文件上传
        upload.render({
            elem: '#upFile',
            url: '/admin/fileinfo/upload/image',
            exts:'apk',
            size:1024*100,
            accept: 'file', //普通文件
            progress:function(value){//上传进度回调 value进度值
                element.progress('demo', value+'%')//设置页面进度条
            },
            choose: function (obj) {
                apkFile = null;
                //预览
                obj.preview(function (index, file, result) {
                })
            },
            done: function (res,index, upload) { //上传完成
                layer.msg('上传成功',{
                    icon:1,
                    time:800
                });
                apkFile=res.data.package;
                $("#apkPackage").val(apkFile);
                package=res.data.package;
                versionName=res.data.versionName;
                versionCode=res.data.versionCode;
                MD5=res.data.MD5;
                filePath=res.data.filePath;
            }
        });
</script>

</html>